package com.zuorenke.vertx.factory;

import com.zuorenke.help.SpringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeansException;

/**
 * @author Z.R.K
 * @description
 * @create 2019-05-17 15:51:54
 **/
@Slf4j
public class BeanFactory {
	private BeanFactory(){}
	public static Object builder(Class clazz){
		Object t = null;
		try{
			t = SpringUtils.getBean(clazz);
		}catch (BeansException e){
			log.info("{} bean not found, create it", clazz.getName());
		}
		if(t == null){
			try {
				t = clazz.newInstance();
			} catch (InstantiationException e) {
				log.error("InstantiationException {}", e);
			} catch (IllegalAccessException e) {
				log.error("IllegalAccessException {}", e);
			}
		}
		return t;
	}
}
